
def isPrime(a):   
    if a == 1: return False   
    test = True   
    в = a - 1   
    while в > 1:   
        if not a % в:   
            test = False               
            break   
        в -= 1       
    return test  
     
n = input() 
r = [] 
for i in range(len(n) + 1): 
    for в in range(i,len(n) + 1): 
        if i == в: 
            continue 
        a = int(n[i:в]) 
        if isPrime(a): 
            r += [a] 
print(max(r) if r else 0)
